package com.st.valid.mapstruct.test;

import com.st.valid.entity.*;
import com.st.valid.service.ItemConverter;
import com.st.valid.service.PersonConverter;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.junit.Test;

import java.text.MessageFormat;
import java.util.*;


/**
 * @创建人: 放生
 * @创建时间: 2022/4/2
 * @描述:
 */
@Slf4j
public class TT {

    @Test
    public  void test01() {

        Person person = new Person(1L,"fangSheng","zhige.me@gmail.com",new Date(),new User(1));
		PersonDTO personDTO = PersonConverter.INSTANCE.domain2dto(person);
        log.info(personDTO.toString());
        log.info(personDTO.getId()+":::"+person.getId());
        log.info(personDTO.getName()+":::"+person.getName());
        log.info(personDTO.getBirth()+":::"+ person.getBirthday());


		String format = DateFormatUtils.format(personDTO.getBirth(), "yyyy-MM-dd HH:mm:ss");
        log.info(personDTO.getBirthDateFormat()+":::"+format);
        log.info(personDTO.getBirthExpressionFormat()+":::"+format);


		List<Person> people = new ArrayList<>();
		people.add(person);
		List<PersonDTO> personDTOs = PersonConverter.INSTANCE.domain2dto(people);




    }

    @Test
    public void test02(){

        Item item = new Item(1L, "iPhone X");
        Sku sku = new Sku(2L, "phone12345", 1000000);
        SkuDTO skuDTO = ItemConverter.INSTANCE.domain2dto(item, sku);
        log.info(skuDTO.toString());
        log.info(skuDTO.getSkuId()+":::"+ sku.getId());
        log.info(skuDTO.getSkuCode()+":::"+ sku.getCode());
        log.info(skuDTO.getSkuPrice()+":::"+ sku.getPrice());
        log.info(skuDTO.getItemId()+":::"+ item.getId());
        log.info(skuDTO.getItemName()+":::"+ item.getTitle());

    }

    @Test
    public void test03(){
        // 测试类 PersonConverterTest 加入
        log.info(PersonConverter.INSTANCE.convert2Bool(1)+"");
        log.info((int)PersonConverter.INSTANCE.convert2Int(true)+"");


    }

    @Test
    public void test04(){
        //获取默认的语言环境
        Locale aDefault = Locale.getDefault();
        System.out.println(aDefault);
        System.out.println("------------------------------------");
//       获取所有 jdk 支持的语言环境
//        Locale[] availableLocales = Locale.getAvailableLocales();
//        for (int i = 0; i < availableLocales.length; i++) {
//            System.out.println(availableLocales[i]);
//        }


        System.out.println(Locale.CHINA);
        System.out.println(Locale.US);

        // 取得系统默认的国家语言
        //Locale locale = Locale.getDefault(Locale.Category.FORMAT);
        ResourceBundle message = ResourceBundle.getBundle("messages", Locale.US);
        System.out.println(message.getString("hello"));

        System.out.println("----------------------------------");
        String msg = message.getString("say");
        String result = MessageFormat.format(msg, "China", "I Love you");

        System.out.println(result);




    }





}
